package com.linwen.excise.leetcode;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName _94二叉树的中序遍历
 * @Description TODO
 * @Author zero
 * @DATE 2024/4/7 3:14 AM
 * @Version 1.0
 */
public class _94二叉树的中序遍历 {
    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(1);
        TreeNode treeNode1 = new TreeNode(2);
        TreeNode treeNode2 = new TreeNode(3);
        treeNode.right = treeNode1;
        treeNode1.left = treeNode2;
        System.out.println(inorderTraversal(treeNode));
    }
    public static List<Integer> inorderTraversal(TreeNode root) {
        ArrayList<Integer> result = new ArrayList<>();
        function(root,result);
        return result;
    }

    private static void function(TreeNode root, ArrayList<Integer> result) {
        if(root==null){
            return;
        }
        function(root.left,result);
        result.add(root.val);
        function(root.right,result);
    }
}
